# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=hostapd
pkgver=2.11
pkgrel=0
pkgdesc="daemon for wireless software access points"
url="https://w1.fi/hostapd/"
arch="all"
license="BSD-3-Clause"
makedepends="openssl-dev>3 libnl3-dev linux-headers"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://w1.fi/releases/hostapd-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"
options="!check" #no testsuite
builddir="$srcdir"/$pkgname-$pkgver/hostapd

# secfixes:
#   2.10-r0:
#     - CVE-2022-23303
#     - CVE-2022-23304
#   2.9-r3:
#     - CVE-2021-30004
#   2.9-r2:
#     - CVE-2020-12695
#   2.9-r1:
#     - CVE-2019-16275
#   2.8-r0:
#     - CVE-2019-11555
#     - CVE-2019-9496
#   2.6-r2:
#     - CVE-2017-13077
#     - CVE-2017-13078
#     - CVE-2017-13079
#     - CVE-2017-13080
#     - CVE-2017-13081
#     - CVE-2017-13082
#     - CVE-2017-13086
#     - CVE-2017-13087
#     - CVE-2017-13088

prepare() {
	default_prepare

	sed -i -e "s:/etc/hostapd:/etc/hostapd/hostapd:g" \
		hostapd.conf

	# toolchain setup
	{
		sed \
			-e '/^#CONFIG_RADIUS_SERVER=y/s/^#//' \
			-e '/^#CONFIG_DRIVER_WIRED=y/s/^#//' \
			-e '/^#CONFIG_DRIVER_NONE=y/s/^#//' \
			-e '/^#CONFIG_IEEE80211N=y/s/^#//' \
			-e '/^#CONFIG_IEEE80211R=y/s/^#//' \
			-e '/^#CONFIG_IEEE80211AC=y/s/^#//' \
			-e '/^#CONFIG_IEEE80211AX=y/s/^#//' \
			-e '/^#CONFIG_FULL_DYNAMIC_VLAN=y/s/^#//' \
			-e '/^#CONFIG_LIBNL32=y/s/^#//' \
			-e '/^#CONFIG_ACS=y/s/^#//' \
			-e '/^#CONFIG_WEP=y/s/^#//' \
			-e '/^#CONFIG_SAE=y/s/^#//' \
			-e '/^#CONFIG_ELOOP_EPOLL=y/s/^#//' \
			-e '/^#CONFIG_FST=y/s/^#//' \
			-e '/^#CONFIG_FST_TEST=y/s/^#//' \
			-e '/^#CONFIG_MBO=y/s/^#//' \
			-e '/^#CONFIG_WPA_CLI_EDIT=y/s/^#//' \
			-e '/^#CONFIG_AIRTIME_POLICY=y/s/^#//' \
			defconfig

		echo "CC ?= ${CC:-gcc}"
		echo "CFLAGS += -I/usr/include/libnl3"
		echo "LIBS += -L/usr/lib"
	} >> .config
}

build() {
	export CFLAGS="$CFLAGS -flto=auto"

	make all nt_password_hash
}

package() {
	install -D hostapd.conf \
		hostapd.accept \
		hostapd.deny \
		hostapd.eap_user \
		hostapd.radius_clients \
		hostapd.sim_db \
		hostapd.wpa_psk \
		-t "$pkgdir"/etc/hostapd/

	install -Dm755 hostapd \
		-t "$pkgdir"/usr/sbin/
	install -Dm755 hostapd_cli nt_password_hash \
		-t "$pkgdir"/usr/bin/

	install -Dm755 "$srcdir"/hostapd.initd \
		"$pkgdir"/etc/init.d/hostapd
	install -Dm644 "$srcdir"/hostapd.confd \
		"$pkgdir"/etc/conf.d/hostapd

	install -Dm644 hostapd.8 \
		-t "$pkgdir"/usr/share/man/man8/
	install -Dm644 hostapd_cli.1 \
		-t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
1382af2a243e3a555507b55942f41d1233cc942826d26bc4f4dbe5e75560b3fe22e426948762fe162453e934685a69ef0c05723b7fecef71811fc1987e32b048  hostapd-2.11.tar.gz
adeca34c6254ac6fccd84e6f08f8c394225e1b89e2c8771b46da5c85fe3fdabc568628530c39da3ab30b72e98891b07bbdb63f74217e79d6afb9796715d822f1  hostapd.initd
250b072ae26892d5ba285d717d2742a29c12d52db59f021ff18a5eff709827f9987965539bf3f7b83c03fb8c103ea49604118a1d15056e6f1d8a7ae8043affbb  hostapd.confd
"
